﻿using System;
using System.Collections.Generic;
using System.Text;
using FreeImageAPI;

namespace Imagenator.Controls
{
	class ImageFormatComboBox : ArgusLib.Controls.EnumComboBox<FreeImageAPI.FREE_IMAGE_FORMAT>
	{
		public ImageFormatComboBox()
			: base() { }

		protected override string FormatEnum(FREE_IMAGE_FORMAT value)
		{
			if (this.DesignMode == false)
			{
				if (value == FREE_IMAGE_FORMAT.FIF_UNKNOWN)
					return "Same as input format";
				string ext = FreeImage.GetPrimaryExtensionFromFIF(value);
				if (string.IsNullOrEmpty(ext) == false)
					ext = " (*." + ext + ')';
				return FreeImage.GetFIFDescription(value) + ext;
			}
			return base.FormatEnum(value);
		}

		protected override bool IsValidValue(FREE_IMAGE_FORMAT value)
		{
			if (value == FREE_IMAGE_FORMAT.FIF_UNKNOWN)
				return true;

			if (FreeImage.IsAvailable() == true)
				return FreeImage.FIFSupportsWriting(value);
			return false;
		}
	}

	class ImageTypeComboBox : ArgusLib.Controls.EnumComboBox<FreeImageAPI.FREE_IMAGE_TYPE>
	{
		FREE_IMAGE_FORMAT format;
		public ImageTypeComboBox()
			: base()
		{
			this.format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
		}

		public void SetFormat(FREE_IMAGE_FORMAT format)
		{
			this.format = format;
			this.Populate();
		}

		protected override string FormatEnum(FREE_IMAGE_TYPE value)
		{
			return value.ToString().Substring(4);
		}

		protected override bool IsValidValue(FREE_IMAGE_TYPE value)
		{
			if (FreeImage.IsAvailable() == true)
				return FreeImage.FIFSupportsExportType(this.format, value);
			return false;
		}
	}

	class FilterComboBox : ArgusLib.Controls.EnumComboBox<FREE_IMAGE_FILTER>
	{
		public FilterComboBox()
			: base() { }

		protected override string FormatEnum(FREE_IMAGE_FILTER value)
		{
			return value.ToString().Substring(7);
		}
	}

	class JpegQualityComboBox : ArgusLib.Controls.EnumComboBox<JpegQuality>
	{
		public JpegQualityComboBox()
			: base() { }
	}

	class JpegSubsamplingComboBox : ArgusLib.Controls.EnumComboBox<JpegSubsampling>
	{
		public JpegSubsamplingComboBox()
			: base() { }
	}

	class PngCompressionComboBox : ArgusLib.Controls.EnumComboBox<PngCompression>
	{
		public PngCompressionComboBox()
			: base() { }
	}

	class ExrCompressionComboBox : ArgusLib.Controls.EnumComboBox<ExrCompression>
	{
		public ExrCompressionComboBox()
			: base() { }
	}
}
